let fs = require('fs')
const filename=__dirname+'/demo/demo.txt';
//highWaterMark 设置
const readStream = fs.createReadStream(filename,{highWaterMark:1});
const fileWriteName = __dirname + '/demo/demo2.txt';
const writeStream = fs.createWriteStream(fileWriteName);
readStream.pipe(writeStream)
// //写入数据
// writeStream.write("0000", () => {
//         console.log('数据写完了000')
//     })
// //监听写入关闭的操作
// writeStream.on('close', (fd) => {
//     console.log('文件关闭了', fd)
// })

// writeStream.end()
// //监听文件写入完成
// writeStream.on('end', () => {
//     console.log('当数据被清空之后')
// })
// let data = ''
// //监听文件流传输
// readStream.on('data',(chunk)=>{
//     console.log('=========')
//     data = data + chunk;
// })
// readStream.on('end',(chunk)=>{
//     console.log('file read end')
// })
// readStream.on('error',(err)=>{
//     console.log(err)
// })